/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgPet
    {
        private readonly Dictionary<int, CfgPet> _dataMap;
        private readonly List<CfgPet> _dataList;


        public TbCfgPet(ByteBuf _buf)
        {
            //first read common data
            _TbCommonPet _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonPet(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgPet>(size * 3 / 2);
            _dataList = new List<CfgPet>(size);

            for (int i = 0; i < size; i++)
            {
                CfgPet _v;
                _v = CfgPet.DeserializeCfgPet(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgPet> DataMap => _dataMap;
        public IReadOnlyList<CfgPet> DataList => _dataList;

        public CfgPet Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgPet] config not found,id:" + key.ToString());

            return null;
        }

        public CfgPet GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "pet";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgPet LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgPet(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgPet
    {
        private CfgPet(ByteBuf _buf, _TbCommonPet _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Type = (PetType)(_buf.ReadInt());
            TypeName = TableCenter.GetI18NText(_buf.ReadInt());
            Sort = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; PetHalfBodyImage = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; BattleEntityAsset = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; UIEntityAsset = _commonData._field3[dataIndex]; }
            InitialLevel = _buf.ReadInt();
            LevelLimit = _buf.ReadInt();
            SkillID = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; AttType = _commonData._field4[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; AttValue = _commonData._field5[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; RandomPabilityNum = _commonData._field6[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; RandomPabilityUnlockLv = _commonData._field7[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; RandomPabilitySlotUnlockLv = _commonData._field8[dataIndex]; }
            ExtraSlotNum = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ReleaseReward = _commonData._field9[dataIndex]; }

            PostInit();
        }

        internal static CfgPet DeserializeCfgPet(ByteBuf _buf, _TbCommonPet _commonData)
        {
            return new CfgPet(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 宠物默认名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 类型
        /// </summary>
        public PetType Type { get; private set; }
        /// <summary>
        /// 类型名称
        /// </summary>
        public string TypeName { get; private set; }
        /// <summary>
        /// 显示排序
        /// </summary>
        public int Sort { get; private set; }
        /// <summary>
        /// 头像图标
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 半身像
        /// </summary>
        public string PetHalfBodyImage { get; private set; }
        /// <summary>
        /// 战斗实体资源名
        /// </summary>
        public string BattleEntityAsset { get; private set; }
        /// <summary>
        /// UI实体资源名
        /// </summary>
        public string UIEntityAsset { get; private set; }
        /// <summary>
        /// 初始等级（默认1）
        /// </summary>
        public int InitialLevel { get; private set; }
        /// <summary>
        /// 等级上限
        /// </summary>
        public int LevelLimit { get; private set; }
        /// <summary>
        /// 专属主动技能（默认解锁）
        /// </summary>
        public int SkillID { get; private set; }
        /// <summary>
        /// 专属属性1类型
        /// </summary>
        public IReadOnlyList<int> AttType { get; private set; }
        /// <summary>
        /// 专属属性1值
        /// </summary>
        public IReadOnlyList<int> AttValue { get; private set; }
        /// <summary>
        /// 各随机属性组，随机属性数量（同组中结果不可重复，不同组中不可存在相同id属性）
        /// </summary>
        public IReadOnlyList<int> RandomPabilityNum { get; private set; }
        /// <summary>
        /// 各随机属性组解锁等级
        /// </summary>
        public IReadOnlyList<int> RandomPabilityUnlockLv { get; private set; }
        /// <summary>
        /// 可通过等级解锁的随机被动槽位对应解锁等级（数组长度为可通过等级解锁的槽位数量）
        /// </summary>
        public IReadOnlyList<int> RandomPabilitySlotUnlockLv { get; private set; }
        /// <summary>
        /// 可通过道具解锁的随机被动槽位数量
        /// </summary>
        public int ExtraSlotNum { get; private set; }
        /// <summary>
        /// 放生宠物可获取的基础奖励
        /// </summary>
        public IReadOnlyList<int> ReleaseReward { get; private set; }

        /// <summary>
        /// Icon资源全路径
        /// </summary>
        public string Icon_fullPath => $"Res/05_Images/Sprite/{Icon}";
        /// <summary>
        /// PetHalfBodyImage - 全路径
        /// </summary>
        public string PetHalfBodyImage_fullPath => $"Res/05_Images/Texture/UIPetRes/UIPetHalfBody/{PetHalfBodyImage}";
        /// <summary>
        /// Asset资源全路径
        /// </summary>
        public string UIEntityAsset_fullPath => $"Res/03_Prefabs/UI/PetModel3D/{UIEntityAsset}.prefab";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonPet
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field5 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field6 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field7 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field8 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field9 { get; private set; }
        internal _TbCommonPet(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field7 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field8 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field9 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
